"""
存放的是 首页 元素的定位方式 和 元素的操作
"""
from selenium.webdriver.common.by import By
from common.Base import Base, open_browser
from selenium.webdriver.common.action_chains import ActionChains

home_url = "http://localhost:8080/ecshop/index.php"


class Home_page(Base):
    sy_location = ("link text", "首页")  # 定位 首页
    jydq_location = ("link text", "家用电器")  # 定位 家用电器
    djd_location = ("xpath", "//*[@id='category_tree']/div[1]/div[2]/div/a")  # 定位 子目录大家电
    smss_location = ("link text", "数码时尚")  # 定位数码时尚
    znyj_location = ("link text", "智能硬件")  # 定位智能硬件
    yddy_location = ("link text", "移动电源")  # 定位移动电源
    sjlx_location = ("link text", "手机类型")  # 定位手机类型
    sxsj_location = ("xpath", "//*[@id='category_tree']/div[5]/div[2]/div[1]/a")  # 定位子目录小型手机
    g3sj_location = ("xpath", "//*[@id='category_tree']/div[5]/div[2]/div[2]/a")  # 定位子目录3G手机
    sj_location = ("link text", "手机")  # 定位手机
    ej_location = ("xpath", "//*[@id='category_tree']/div[6]/div[2]/div[1]/a")  # 定位子目录耳机
    dc_location = ("xpath", "//*[@id='category_tree']/div[6]/div[2]/div[2]/a")  # 定位子目录电池
    czk_location = ("link text", "充值卡")  # 定位充值卡
    fz_location = ("link text", "服装")  # 定位服装
    pj_location = ("link text", "配件")  # 定位配件
    zsmss_location = ("xpath", "//*[@id='category_tree']/div[9]/div[2]/div[1]/a")  # 定位子目录数码时尚
    bhk_location = ("xpath", "//*[@id='category_tree']/div[9]/div[2]/div[2]/a")  # 定位子目录保护壳

    # 定位 搜索框
    search_location = ("id", "keyword")
    # 定位 搜索按钮
    submit_location = ("name", "imageField")

    def input_search(self, goodsname):
        self.send_text(self.search_location, goodsname)
        self.click(self.submit_location)

    # 定位点击首页
    def click_SY(self):
        self.click(self.sy_location)

    # 定位 点击家用电器
    def click_JYDQ(self):
        self.click(self.jydq_location)

    # 定位 点击 大家电
    def click_DJD(self):
        ActionChains(self.driver).move_to_element(self.find_elements(self.jydq_location)[1]).perform()
        self.text = self.get_element_text(self.djd_location)
        self.click(self.djd_location)

    # 定位点击 数码时尚
    def click_SMSS(self):
        self.click(self.smss_location)

    # 定位点击 智能硬件
    def click_ZNYJ(self):
        self.click(self.znyj_location)

    # 定位并点击 移动电源
    def click_YDDY(self):
        self.click(self.yddy_location)

    # 定位 点击 手机类型
    def click_SJLX(self):
        self.click(self.sjlx_location)

    # 定位 点击 小型手机
    def click_XSSJ(self):
        ActionChains(self.driver).move_to_element(self.find_element(self.sjlx_location)).perform()
        self.text = self.get_element_text(self.sxsj_location)
        self.click(self.sxsj_location)

    # 定位 点击 3G手机
    def click_SGSJ(self):
        ActionChains(self.driver).move_to_element(self.find_element(self.sjlx_location)).perform()
        self.text = self.get_element_text(self.g3sj_location)
        self.click(self.g3sj_location)

    # 定位 点击 手机
    def click_SJ(self):
        self.click(self.sj_location)

    # 定位 点击 耳机
    def click_EJ(self):
        ActionChains(self.driver).move_to_element(self.find_element(self.sj_location)).perform()
        self.text = self.get_element_text(self.ej_location)
        self.click(self.ej_location)

    # 定位 点击 电池
    def click_DC(self):
        ActionChains(self.driver).move_to_element(self.find_element(self.sj_location)).perform()
        self.text = self.get_element_text(self.dc_location)
        self.click(self.dc_location)

    # 定位点击充值卡
    def click_CZK(self):
        self.click(self.czk_location)

    # 定位并 点击 服装
    def click_FZ(self):
        self.click(self.fz_location)

    # 定位点击配件
    def click_PJ(self):
        self.click(self.pj_location)

    # 定位 点击 子目录数码时尚
    def click_ZSMSS(self):
        ActionChains(self.driver).move_to_element(self.find_element(self.pj_location)).perform()
        self.text = self.get_element_text(self.zsmss_location)
        self.click(self.zsmss_location)

    # 定位 点击 子目录保护壳
    def click_BHK(self):
        ActionChains(self.driver).move_to_element(self.find_element(self.pj_location)).perform()
        self.text = self.get_element_text(self.bhk_location)
        self.click(self.bhk_location)


if __name__ == '__main__':  # 测试
    driver = open_browser()
    lp = Home_page(driver)
    lp.open_url(home_url)
    # lp.input_search("1322")

    # lp.click_SY()
    # lp.click_JYDQ()
    # lp.click_ZSMSS()
    # lp.click_ZNYJ()
    # lp.click_YDDY()
    # lp.click_SJLX()
    # lp.click_XSSJ()
    # lp.click_SGSJ()
    # lp.click_BHK()
    # lp.click_DC()
    # lp.click_SJ()
    # lp.click_CZK()
    # lp.click_FZ()
    # lp.click_PJ()
    # lp.click_DJD()
